<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>控制元素样式</title>
    </head>
    <style>
        .cls1 {
            border: 1px solid red;
            width: 100px;
            height: 100px;

        }

        .cls2 {
            border: 1px solid blue;
            width: 200px;
            height: 200px;

        }
    </style>
    <body>
        <!--
        控制元素样式方法:
               1.使用元素的style属性来设置
               2.提前定义好类选择器的样式.通过元素的className属性来设置其class属性值
        -->

        <div id="div1">div</div>
        <div id="div2">div2</div>

        <script>
            //方法1 使用元素的style属性来设置
            var div1 = document.getElementById("div1");
            div1.onclick = function () {
                //修改样式
                div1.style.border = "1px solid red";
                div1.style.width = "200px";
                div1.style.fontSize = "50px"
            }

            //方法2 提前定义好类选择器的样式.通过元素的className属性来设置其class属性值
            var div2 = document.getElementById("div2");
            div2.onclick = function () {
                div2.className = "cls2"
            }

        </script>


    </body>
</html>